import { defineStore } from 'pinia'
import { ref } from 'vue'
//用户模块token setToken removeToken
export const useOnlineUsersStore = defineStore('big-OtherUsers', () => {
  //{ username: 'ddd', id: 4 }
  //在线用户的表
  const onlineUsersList = ref([])
  const addUsers = (newUsers) => {
    onlineUsersList.value.push(newUsers)
    ElMessage({
      message: `用户${newUsers.username}已上线`,
      type: 'success',
      plain: true
    })
    console.log('目前在线用户是:')
    console.log(onlineUsersList.value)
  }
  const initUsers = (newUsersList) => {
    onlineUsersList.value = newUsersList
    console.log('目前在线用户是:')
    console.log(onlineUsersList.value)
  }
  const removeUsers = (userName) => {
    onlineUsersList.value = onlineUsersList.value.filter(
      (item) => item.userName !== userName
    )
    ElMessage({
      message: `用户${userName}已下线`,
      type: 'info',
      plain: true
    })
  }
  return {
    onlineUsersList,
    addUsers,
    removeUsers,
    initUsers
  }
})
